<?php
header("Content-Type: application/json; charset=UTF-8");
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
$tableName = "document_form";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql = "SELECT * FROM $tableName";
    $stmt = $conn->query($sql); 
    $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    if (count($data) > 0) {
        echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
    } else {
        echo json_encode(['error' => '未找到数据'], JSON_UNESCAPED_UNICODE);
    }
} catch(PDOException $e) {
    http_response_code(500);
    echo json_encode(['error' => '数据库错误: ' . $e->getMessage()], JSON_UNESCAPED_UNICODE);
} catch(Exception $e) {
    http_response_code(400);
    echo json_encode(['error' => $e->getMessage()], JSON_UNESCAPED_UNICODE);
}

$conn = null;
?>    